- Published on
Priority Scheduling Algorithm
- Authors
- Name
- Vishok Manikantan
Hello folks! I have a lab practical on the Priority Scheduling algorithm tomorrow, and I thought of sharing my understanding of the algorithm with you all.
In this blog post, we will see how the Priority Scheduling algorithm works in Operating Systems.
What is Priority Scheduling?
Priority Scheduling is a non-preemptive algorithm where the process...... [STOP]
Wait, what is preemptive? 🤔
Well, basically, preemptive means that the process can be stopped at any time and the CPU can be given to another process. It is like when you are watching your favorite TV show and your mom asks you to do the dishes. You have to stop watching the show and do the dishes. That's preemptive. The CPU can interrupt the process and give it to another process.
Just like how i broke the flow of definition of Priority Scheduling, and started talking about more basic and important concept - Preemptive, the same way the CPU can break the flow of execution of a process and give it to another process. This is called Preemptive Scheduling.
So, Priority Scheduling is a non-preemptive algorithm where the process with the highest priority is executed first.
Formal Definition of Preemptive Scheduling: It is a type of scheduling where the tasks with higher priority are assigned the CPU first and the tasks with lower priority are assigned the CPU only when the higher priority tasks are not in the ready state.
How does Priority Scheduling work?
In Priority Scheduling, each process is assigned a priority
. The priority
is an unsigned integer value that determines the importance of the process. The process with the highest priority is executed first. Highest priority
is 0 and the lowest priority can be n-1, where n is the total number of processes. Think of it like JEE rank, the lower the rank number, the higher the priority.
The priority
can be assigned based on various factors such as:
- Time to complete the process
- Memory requirements
- Importance of the process
- Deadline of the process
- If it is batman or superman
- etc.
The process with the highest priority is selected for execution. If two processes have the same priority, the process that arrived first is selected for execution. This is called First Come First Serve (FCFS).
Example
Let's consider the following processes:
Process ID | Arrival Time | Burst Time | Priority |
---|---|---|---|
P1 | 0 | 11 | 2 |
P2 | 5 | 28 | 0 |
P3 | 12 | 2 | 3 |
P4 | 2 | 10 | 1 |
P5 | 9 | 16 | 4 |
The processes are scheduled based on their priority. The process with the highest priority is executed first.
Now look at this awesome simulation i made:
In the above simulation, we have 5 processes with their arrival time, burst time, and priority. The processes are sorted based on their priority and executed in that order.
Conclusion
Priority Scheduling is a simple and efficient scheduling algorithm that assigns the CPU to the process with the highest priority. It is a non-preemptive algorithm, meaning that once a process starts executing, it will continue until it completes or is blocked.